package com.example.accessibilitydemo.util;

import java.util.Vector;

public class ThreadPools {
	private static ThreadPools instance;
	private int TPMAX = 10;
	private int currentcount = 0;
	private boolean isstarted;
	private Vector<String> vector = new Vector();

	public static ThreadPools getInstance() {
		if (instance == null)
			instance = new ThreadPools();
		return instance;
	}

	public void addcurrentcount() {
		this.currentcount = (1 + this.currentcount);
	}

	public void addpools(String paramString) {
		if (this.currentcount > -1 + this.TPMAX) {
			this.vector.add(paramString);
			return;
		}
		startthread(paramString);
	}

	public void reducecurrentcount() {
		this.currentcount = (-1 + this.currentcount);
	}

	public void startpools() {
		this.isstarted = true;
		while (true) {
			if (!this.isstarted)
				return;
			if ((this.currentcount < this.TPMAX) && (this.vector.size() > 0))
				startthread((String) this.vector.remove(0));
			try {
				Thread.sleep(500L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public void startthread(String paramString) {
		new Thread() {
			public void run() {
				ThreadPools.this.reducecurrentcount();
			}
		}.start();
		addcurrentcount();
	}

	public void stoptpools() {
		this.isstarted = false;
		this.vector.clear();
	}
}